package com.ruoyi.member.controller;

import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.member.domain.MyMap;
import com.ruoyi.member.service.ISellerMyOrderService;
import com.ruoyi.member.service.impl.SellerMyOrderServiceImpl;
import org.apache.tomcat.websocket.WsSession;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author huang
 * @Date 2023/8/16 14:08
 * @PackageName: com.ruoyi.member.controller
 * @ClassName: MapWebsocket
 * @Description:
 * @Version 1.0
 */

@ServerEndpoint("/getMap")
@Component
public class MapWebsocket {

    //记录连接的客户端
    public static Session client;

    public static int status = 0;


    @OnOpen
    public void onOpen(Session session) {
        MapWebsocket.client = session;
        MapWebsocket.status = 1;
    }

    /**
     * 连接关闭调用的方法
     */
    @OnClose
    public void onClose() {
        MapWebsocket.status = 0;
        System.out.println("结束");
    }


    /**
     * 判断是否连接的方法
     * @return
     */
    public static boolean isServerClose() {
        if (MapWebsocket.status == 0) {
            return true;
        }else {
            return false;
        }
    }

    public static void getMap(String msg) {
        try {
            MapWebsocket.client.getBasicRemote().sendText(msg);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
